package com.vf.admin.utils.sendsms;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.vf.admin.common.Constants;

/**
 * 阿里云发送短信
 */
public class SendSms {
    public static IAcsClient client;//
    static{
        DefaultProfile profile = DefaultProfile.getProfile(Constants.aliyun_sms_RegionId, Constants.aliyun_sms_accessKeyId, Constants.aliyun_sms_secret);
        client = new DefaultAcsClient(profile);
    }
    public static SendSms getInstance(){
        return new SendSms();
    }

    public static void main(String[] args){
        SendSms sms = new SendSms();
        boolean a  = sms.sendSMS("15038309303","1234");
        System.out.println("XXXXXXXXXXX"+a);
    }
    /**
     * 发送短信
     * @param
     *      phone  手机号
     *      code   验证码
     */
    public boolean sendSMS(String phone,String code){
//        System.out.println("手机号:"+phone+"   验证码:"+code);
//        CommonRequest request = new CommonRequest();
//        request.setMethod(MethodType.POST);
//        request.setDomain("dysmsapi.aliyuncs.com");
//        request.setVersion("2017-05-25");
//        request.setAction("SendSms");
//        request.putQueryParameter("RegionId", Constants.aliyun_sms_RegionId);
//        request.putQueryParameter("PhoneNumbers", phone);
//        request.putQueryParameter("SignName", Constants.aliyun_sms_SignName);
//        request.putQueryParameter("TemplateCode", Constants.aliyun_sms_TemplateCode);
//        request.putQueryParameter("TemplateParam", "{code:'"+code+"'}");
//        try {
//            CommonResponse response = client.getCommonResponse(request);
//            ResultSMS resultSMS = JSON.parseObject(response.getData(), ResultSMS.class);
//            System.out.println(resultSMS.getCode());
//            System.out.println(resultSMS.getMessage());
//            if(StringEx.isNotNull(resultSMS.getCode()) && resultSMS.getCode().trim().equals("OK")){
//                return true;
//            }
//        } catch (ServerException e) {
//            e.printStackTrace();
//            System.out.println(e);
//            return false;
//        } catch (ClientException e) {
//            e.printStackTrace();
//            System.out.println(e);
//
//            return false;
//        }
        return false;
    }

}